#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef  long long LL;
const int inf = 1 << 30;
const LL maxn = 30010;

int N, M;
vector<int> es[maxn], topo;
int in[maxn];
void topoSort() {

    topo.clear();
    priority_queue<int, vector<int>, less<int> > q;
    for (int i = 1; i <= N; i++)
        if (in[i] == 0)
            q.push(i);
    while (!q.empty()) {
        int u = q.top();
        q.pop();
        topo.push_back(u);
        for (int i = 0; i < es[u].size(); i++) {
            int v = es[u][i];
            --in[v];
            if (in[v] == 0) q.push(v);
        }
    }
}
int main()
{
    int a, b, T;
    scanf("%d", &T);
    while (T--) {
        ms(es, 0); ms(in, 0);
        scanf("%d%d", &N, &M);
        for (int i = 1; i <= M; i++) {
            scanf("%d%d", &a, &b);
            es[b].push_back(a);     //反向建图
            ++in[a];
        }
        topoSort();
        for (int i = topo.size() - 1; i >= 0; i--) {
            if (i == 0) printf("%d", topo[i]);
            else printf("%d ", topo[i]);
        }
        printf("\n");
    }

    return 0;
}
